<?php

require_once '../../classes/includeAll_Layer2.php';
require_once '../../resources/getConnection.php';

$function  = filter_input(INPUT_POST,"function");
$message = "";
$success = "";
switch($function)
{
    case 'delete':    
         $deviceID = filter_input(INPUT_POST,"deviceID");
        
         if($deviceID == null || $deviceID == false || !$isAdmin)
         {
              $success = "false";
         }else
         {
            $device = new Device($deviceID, $connection);
            if($device->DeletDevice())
            {
               $success = "true"; 
            }
         }    
    break;

    case 'deleteChecked':
        $successArr = array();
        if(isset( $_POST['del']))
        {
            
            $deleteArray = $_POST['del'];
                    foreach($deleteArray  as $key => $value) 
                    {
                        $device = new Device($key, $connection);
                        if($device->DeletDevice())
                        {
                            array_push($successArr, $key);
                        }
                    }    
                    $success = "true"; 
                     $message = $successArr;
        }else
        {
            $success = "false"; 
            $message = "Kein Gerät ausgewählt";
        }
    break;
      
    default:
        $success = "false";
        $message ="Ungültige Anweisung";
    break;
}
echo json_encode (array("success"=>$success, "message"=>$message));

$connection->disconnectDB();
?>



